package com.ehotting.mqbd.core.config;

import com.ehotting.eaf.netty.loggers.NettyMsgReceiveLogger;
import com.ehotting.eaf.netty.loggers.NettyMsgSendLogger;
import com.ehotting.eaf.redis.service.RedisService;
import com.ehotting.mqbd.api.bean.MQDataAble;
import com.ehotting.mqbd.core.helper.RocketMQAdminHelper;
import com.ehotting.mqbd.core.logger.MqMsgLogger;
import com.ehotting.mqbd.core.logger.SolverMsgLogger;
import com.ehotting.mqbd.core.manager.*;
import com.ehotting.mqbd.core.logger.MQSendLogger;
import com.ehotting.mqbd.core.service.MQService;
import com.ehotting.mqbd.core.service.SolverInfoService;
import com.ehotting.mqbd.core.service.TaskStateMQService;
import com.ehotting.mqbd.core.sync.MqSyncFutureMapHelper;
import com.ehotting.mqbd.core.sync.TcpClientMapHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
@DependsOn("mqbdCorePropertyConfig")
public class MqbdCoreConfig {

    @Bean(name="mqSyncFutureMapHelper",initMethod = "start",destroyMethod = "stop")
    public MqSyncFutureMapHelper<MQDataAble> mqSyncFutureMapHelper(){
        return new MqSyncFutureMapHelper();
    }

    @Bean(name="tcpClientMapHelper",initMethod = "start",destroyMethod = "stop")
    public TcpClientMapHelper tcpClientMapHelper(){
        return new TcpClientMapHelper();
    }


    @Bean("solverAllocator")
    public SolverAllocator solverAllocator(SolverStateManager solverStateManager,SolverInfoManager solverInfoManager, MsgStateManager msgStateManager,
                                           RedisService redisService){
        SolverAllocator solverAllocator = new SolverAllocator(solverStateManager, solverInfoManager,msgStateManager,redisService);
        return solverAllocator;
    }

    @Bean("solverInfoManager")
    @DependsOn({"mqbdCorePropertyConfig","moduleManager"})
    public SolverInfoManager solverInfoManager(MqbdCoreServerInfoConfig mqbdCorePropertyConfig, ModuleManager moduleManager,
                                               SolverInfoService solverInfoService){
        SolverInfoManager solverInfoManager = new SolverInfoManager(mqbdCorePropertyConfig,moduleManager,solverInfoService);
        return solverInfoManager;
    }

    @Bean
    public MQSendLogger mqSendLogger(){
        return new MQSendLogger("MQ_SEND_LOGGER");
    }

    @Bean
    public MqMsgLogger mqMsgLogger(){return new MqMsgLogger("MQ_MSG_LOGGER");}

    @Bean
    public NettyMsgReceiveLogger solverMsgLogger(){
        return new NettyMsgReceiveLogger("SOLVER_MSG_LOGGER");
    }

    @Bean
    public NettyMsgSendLogger nettyMsgSendLogger(){
        return new NettyMsgSendLogger("NETTY_SEND_LOGGER");
    }

    @Bean
    public SolverMsgLogger solverLogger(){
        return new SolverMsgLogger("SOLVER_MSG_LOGGER");
    }

    @Bean
    public SolverStateManager solverStateManager(SolverInfoManager solverInfoManager){
        SolverStateManager solverStateManager = new SolverStateManager(solverInfoManager);
        return solverStateManager;
    }

    @Bean
    public SolverCountManager solverCountManager(SolverInfoManager solverInfoManager,RedisService redisService){
        SolverCountManager solverCountManager = new SolverCountManager(redisService,solverInfoManager);
        return solverCountManager;
    }

    @Bean(name="rocketMQAdminHelper",initMethod = "start",destroyMethod = "stop")
    public RocketMQAdminHelper rocketMQAdminHelper(MqbdCorePropertyConfig mqbdCorePropertyConfig){
        return new RocketMQAdminHelper(mqbdCorePropertyConfig);
    }



}